﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL_HealthInsurance;
using DTO_HealthInsurance;

namespace HealthInsuranceMgm.Admin
{
    public partial class AddPolicy : System.Web.UI.Page
    {
        DTOPolicies objdtopo = new DTOPolicies();
        BLLPolicies objbllPo = new BLLPolicies();
        BLLCompany objcom = new BLLCompany();
        protected void Page_Load(object sender, EventArgs e)
        {if(!IsPostBack){
            LoadToDropdowlist();
        }
           
        }
        public void LoadToDropdowlist(){
            ddlCompanyId.DataSource = objcom.ListCompany();
           ddlCompanyId.DataTextField ="CompanyName";

           ddlCompanyId.DataValueField = "CompanyId";
                   ddlCompanyId.DataBind();
        }
        public void message(string script)
        {

            Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", script, true);
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                string PolicyName = txtpolicyName.Text;
                string PoliciDes = txtPoDescripton.Text;
                float Amount =  float.Parse(txtAmount.Text);
                float EMi = float.Parse(txtEmi.Text);
                int CompanyId =Int32.Parse( ddlCompanyId.SelectedValue.ToString());
                string medicalid = txtMedicalId.Text;

                objdtopo.PolicyName = PolicyName;
                objdtopo.PolicyDescription = PoliciDes;
                objdtopo.PolicyAmount = Amount;
                objdtopo.PolicyEmi = EMi;
                objdtopo.CompanyId = CompanyId;
                objdtopo.MedicalId = medicalid;

                int i = objbllPo.insertPolicy(objdtopo);

                if (i > 0)
                {

                    message("alert('Insert Succesfull');");

                }
            }
        }
    }
}